#!/usr/bin/env python  
# encoding: utf-8


""" 
@version: v1.0 
@author: Shylock 
@license: Apache Licence  
@contact: JYFelt@163.com 
@site: http://blog.csdn.net/weixin_38034182 
@software: PyCharm Community Edition 
@file: LoginPage.py 
@time: 2017/12/22 11:24 
"""
from tkinter import *
from tkinter.messagebox import *

from MainPage import *


class LoginPage(object):
    def __init__(self, master=None):
        self.root = master  # 定义一个内部变量root
        self.root.geometry('%dx%d' % (300, 180))  # 登录界面窗口大小
        self.username = StringVar()
        self.password = StringVar()
        self.createPage()

    def createPage(self):
        self.page = Frame(self.root)
        self.page.pack()
        Label(self.page).grid(row=0, stick=W)
        Label(self.page, text='账户: ').grid(row=1, stick=W, pady=10)
        Entry(self.page, textvariable=self.username).grid(row=1, column=1, stick=E)
        Label(self.page, text='密码: ').grid(row=2, stick=W, pady=10)
        Entry(self.page, textvariable=self.password, show='*').grid(row=2, column=1, stick=E)
        Button(self.page, text='登陆', command=self.loginCheck).grid(row=3, stick=W, pady=10)
        Button(self.page, text='退出', command=self.page.quit).grid(row=3, column=1, stick=E)

    def loginCheck(self):
        name = self.username.get()
        secret = self.password.get()
        if name == '':
            showwarning(title='无用户名', message='请输入用户名')
        elif secret == '':
            showwarning(title='无密码', message='请输入密码')
        elif name == 'root' and secret == '123456':
            self.page.destroy()
            self.page.destroy()
            MainPage(self.root)
        else:
            showerror(title='错误', message='账号或密码错误！')
